package com.lxmes.flowable.controller;

import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.core.page.TableDataInfo;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.system.domain.SysSp;
import com.lxmes.system.service.ISysSpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 审批流管理Controller
 * 
 * @author ruoyi
 * @date 2023-03-26
 */
@RestController
@RequestMapping("/system/sp")
public class SysSpController extends BaseController
{
    @Autowired
    private ISysSpService sysSpService;

    /**
     * 查询审批流管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sp:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSp sysSp)
    {
        startPage();
        List<SysSp> list = sysSpService.selectSysSpList(sysSp);
        return getDataTable(list);
    }
    //审批流程字段
    @GetMapping("/dictSp")
    public AjaxResult dictSp()
    {
        return AjaxResult.success(sysSpService.selectSysSpDict());
    }
    /**
     * 导出审批流管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sp:export')")
    @Log(title = "审批流管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSp sysSp)
    {
        List<SysSp> list = sysSpService.selectSysSpList(sysSp);
        ExcelUtil<SysSp> util = new ExcelUtil<SysSp>(SysSp.class);
        util.exportExcel(response, list, "审批流管理数据");
    }

    /**
     * 获取审批流管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysSpService.selectSysSpById(id));
    }

    /**
     * 新增审批流管理
     */
    @PreAuthorize("@ss.hasPermi('system:sp:add')")
    @Log(title = "审批流管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSp sysSp)
    {
        return toAjax(sysSpService.insertSysSp(sysSp));
    }

    /**
     * 修改审批流管理
     */
    @PreAuthorize("@ss.hasPermi('system:sp:edit')")
    @Log(title = "审批流管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSp sysSp)
    {
        return toAjax(sysSpService.updateSysSp(sysSp));
    }

    /**
     * 删除审批流管理
     */
    @PreAuthorize("@ss.hasPermi('system:sp:remove')")
    @Log(title = "审批流管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysSpService.deleteSysSpByIds(ids));
    }
}
